package com.jxdinfo.mongodb.controller;

import com.jxdinfo.mongodb.model.MemberReadHistory;
import com.jxdinfo.mongodb.service.MemberReadHistoryService;
import com.jxdinfo.mongodb.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "会员浏览商品记录",description = "会员浏览商品记录描述")
@RestController
@RequestMapping("/history")
public class MemberReadHistoryController {

    @Autowired
    private MemberReadHistoryService memberReadHistoryService;

    @ApiOperation(value = "新增会员浏览商品记录")
    @PostMapping("/create")
    public String create(@RequestBody @ApiParam(value = "浏览记录") MemberReadHistory memberReadHistory){
        String result = memberReadHistoryService.create(memberReadHistory);
        return result;
    }

    @ApiOperation(value = "删除会员浏览商品记录")
    @PostMapping("/delete")
    public int delete(@RequestBody @ApiParam(value = "记录ID集合") List<String> ids){
        int delete = memberReadHistoryService.delete(ids);
        return delete;
    }

    @ApiOperation(value = "修改会员浏览商品记录")
    @PostMapping("/update")
    public int update(@RequestBody @ApiParam(value = "浏览记录") MemberReadHistory memberReadHistory){
        int result = memberReadHistoryService.update(memberReadHistory);
        return result;
    }

    @ApiOperation(value = "查询会员浏览商品记录")
    @GetMapping("/list")
    public List<MemberReadHistory> list(@RequestParam(value = "记录ID") @ApiParam(value = "记录ID") String memberId){
        List<MemberReadHistory> list = memberReadHistoryService.list(memberId);
        return list;
    }

    @ApiOperation(value = "查询所有会员浏览商品记录")
    @GetMapping("/listAll")
    public List<MemberReadHistory> listAll(){
        List<MemberReadHistory> list = memberReadHistoryService.listAll();
        return list;
    }

    @ApiOperation(value = "分页查询所有会员浏览商品记录")
    @PostMapping("/listPage")
    public Page<MemberReadHistory> listPage(@RequestBody @ApiParam(value = "分页")PageUtil<MemberReadHistory> pageUtil){
        return memberReadHistoryService.listPage(pageUtil);
    }

}
